home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1994 March
/
CHIP0394.BIN
/
digital
/
kommunik
/
wwwmac
/
machttp.sit
/
MacHTTP 1.3
/
MacHTTP Software
/
Scripts
/
sample.script
< prev
next >
Wrap
Text File
|
1994-05-01
|
2KB
|
54 lines
-- This script demonstrates using AppleScript with MacHTTP to generate
-- dynamic World Wide Web documents.
--
-- MacHTTP will only read and execute scripts that have been saved as
-- text only. Once the script is loaded by MacHTTP, it is passed to the default
-- scripting system (usually AppleScript) for your server for execution.
-- MacHTTP prepends the script's source code with a line that is the equivalent of:
-- set http_request to "<request from client>"
-- where <request from client> is the actual data received from the WWW client.
--
-- The result of the script execution is then returned to the client as a HTML
-- document. The following script shows how to turn AppleScript results into HTML.
set crlf to (ASCII character 13) & (ASCII character 10)
set http_10_header to "HTTP/1.0 200 OK" & crlf & "Server: MacHTTP" & crlf & ┬
"MIME-Version: 1.0" & crlf & "Content-type: text/html" & crlf & crlf
set file_path to ":Scripts:" -- if this script is in a subdirectory below MacHTTP, change this to the proper relative path
-- Create the title for the HTML document
set header to http_10_header & "<title>Script Test One</title><h1>This is a test:</h1>"
-- Add some text to the body of the document
set body to "This is a test of special chars. See \"Spot\" run! Here's a backslash -> \\"
-- Show the current time on the server
set body to body & "<h2>The time is:</h2>" & (current date)
-- The following shows how to reference the args passed in from MacHTTP
set args to "<h2>Arguments passed in:</h2>" & http_request
set search_args to "<h2>Search arguments:</h2>" & http_search_args
-- Show all the files in the folder "file_path" and turn HTML files into anchors
set filelist to "<h2>Files on the server:</h2><ul>"
set listing to (list folder file file_path)
repeat with i from 1 to the number of items in listing
set one_file to item i of listing
if one_file contains ".html" or one_file contains ".script" then
set filelist to filelist & "<li><a href=\"" & one_file & "\">" & one_file & "</a>"
else
set filelist to filelist & "<li>" & one_file
end if
end repeat
set filelist to filelist & "</ul>"
-- send it all back to the server for transmission to the client
return header & body & args & search_args & filelist